package com.ganzalang.gmall.learning.netty.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @description: 拷贝一张图片
 * @author: Ganzalang
 * @Date 2021/7/13 9:12
 */
public class NIOFileChannel04 {

    public static void main(String[] args) throws IOException {
        // 创建流
        FileInputStream fileInputStream = new FileInputStream("D:\\IDEAProject\\gmall-learning\\gmall-learning-netty\\a.png");
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\IDEAProject\\gmall-learning\\gmall-learning-netty\\b.png");

        // 获取通道
        FileChannel srcChannel = fileInputStream.getChannel();
        FileChannel destChannel = fileOutputStream.getChannel();

        // 从某个通道拷贝到某个通道
        destChannel.transferFrom(srcChannel, 0, srcChannel.size());

        // 关闭通道、流
        srcChannel.close();
        srcChannel.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
